//
//  HNSH_TongZhengViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/26.
//

#import "HNSH_TongZhengViewController.h"

#import "HNSH_TongZhengTopView.h"
#import "HNSH_TongZhengCell.h"
#import "HNSH_TongZhengBottomVIew.h"

#import "HNSH_ExchangeNetServer.h"

@interface HNSH_TongZhengViewController ()

/* topView */
@property (nonatomic, strong) HNSH_TongZhengTopView *topView;
/* bottomView */
@property (nonatomic, strong) HNSH_TongZhengBottomVIew *bottomView;
/* tzModel */
@property (nonatomic, strong) HNSH_TongZhengModel *tzModel;

@end

static NSString *HNSH_TongZhengCellID = @"HNSH_TongZhengCellID";

@implementation HNSH_TongZhengViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadCapitalHdcDataInfo];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self showNavTitle:@"通证" showLeftItem:NO];
    self.navView.backgroundColor = [UIColor clearColor];
    self.navView.titleLabel.textColor = [UIColor colorWithHexString:@"#FFEDD6"];
    
    [self configTableView];
    
//    [self.view addSubview:self.suspensionView];
}

- (void)configTableView {
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    self.tableView.tableHeaderView = self.topView;
    self.tableView.tableFooterView = self.bottomView;
    
    [self.tableView registerClass:[HNSH_TongZhengCell class] forCellReuseIdentifier:HNSH_TongZhengCellID];
}

#pragma mark networking
- (void)loadCapitalHdcDataInfo {
    [HNSH_ExchangeNetServer requestCapitalHdcDataInfoSuccess:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            self.tzModel = [HNSH_TongZhengModel yy_modelWithDictionary:responseObject.resultset];
            self.topView.model = self.tzModel;
            self.bottomView.model = self.tzModel;
            [self.tableView reloadData];
        }
    } Failure:^(NSError * _Nullable error) {
            
    }];
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tzModel.items.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_TongZhengCell *cell = [tableView dequeueReusableCellWithIdentifier:HNSH_TongZhengCellID];
    cell.model = self.tzModel.items[indexPath.row];
    return cell;
}

#pragma mark lazy
- (HNSH_TongZhengTopView *)topView {
    if (!_topView) {
        _topView = [[HNSH_TongZhengTopView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavBarAndStatusBarHeight+248)];
    }
    return _topView;
}

- (HNSH_TongZhengBottomVIew *)bottomView {
    if (!_bottomView) {
        _bottomView = [[HNSH_TongZhengBottomVIew alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 400)];
    }
    return _bottomView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
